﻿function GetConTrol(element) {
    if (arguments.length > 1) {
        for (var i = 0, elements = [], length = arguments.length; i < length; i++)
            elements.push($n(arguments[i]));
        return elements;
    }
    if (typeof element == 'string') {
        var el = document.getElementById(element);
        if (el)
            return el; 7
    }
    else
        return element;

    var regExp = new RegExp('_' + element + '$');
    var formsLength = document.forms.length;
    for (var i = 0; i < formsLength; i++) {
        var form = document.forms[i];
        var elementsLength = form.elements.length;
        for (var j = 0; j < elementsLength; j++) {
            element = form.elements[j];
            if (element.id && element.id.match(regExp))
                return element;
        }
    }
    return null;
}

/**
 * string_pad
 * @param s - String to pad
 * @param l - pad String: Ex "0000" = char "0" len 4
 */
function padding(s,l) {
    return(l.substr(0, (l.length-s.length))+s);
}

function popup(url) {
    var width = 410;
    var height = 450;
    var left = (screen.width - width) / 2;
    var top = (screen.height - height - 100) / 2;
    var params = 'width=' + width + ', height=' + height;
    params += ",left=" + left;
    params += ",top=" + top;
    params += ', directories=no';
    params += ', location=no';
    params += ', menubar=no';
    params += ', resizable=no';
    params += ', scrollbars=no';
    params += ', status=no';
    params += ', toolbar=no';
    //    var params = 'width=' + width + ', height=' + height;
    //    params += ', top=' + top + ', left=' + left;
    //    params += ', directories=no';
    //    params += ', location=no';
    //    params += ', menubar=no';
    //    params += ', resizable=no';
    //    params += ', scrollbars=yes';
    //    params += ', status=no';
    //    params += ', toolbar=no';
    newwin = window.open(url, '_blank', params);
    if (window.focus) { newwin.focus() }
    return false;
}


function Unactive(control1, control2) {
    control1.disabled = control2.disabled = true;
    control1.readOnly = control2.readOnly = true;
    control1.disabled = control2.disabled = true;
    control1.className = control2.className = "disable width_100 grey";
}

function Active(control1, control2) {
    control1.disabled = control2.disabled = false;
    control1.readOnly = control2.readOnly = false;
    control1.disabled = control2.disabled = false;
    control1.className = control2.className = "width_100";
}


function submitenter(e) {
    var keycode;
    if (window.event) keycode = window.event.keyCode;
    else if (e) keycode = e.which;
    else return true;

    if (keycode == 13) {
        document.getElementById("btnLogin").click() ;
        return false;
    }
    else
        return true;
}


function Trim(sString)
{
    while (sString.substring(0,1) ==" ")
    {
        sString = sString.substring(1, sString.length);
    }
    while (sString.substring(sString.length-1, sString.length) ==" ")
    {
        sString = sString.substring(0,sString.length-1);
    }
    return sString;
}



//function check number
function CheckInt(number) {
    var pattern = "0123456789";
    var len = number.value.length;
    if (len != 0) {
        var index = 0;
        while ((index < len) && (len != 0))
            if (pattern.indexOf(number.value.charAt(index)) == -1) {
            if (index == len - 1)
                number.value = number.value.substring(0, len - 1);
            else if (index == 0)
                number.value = number.value.substring(1, len);
            else number.value = number.value.substring(0, index) + number.value.substring(index + 1, len);
            index = 0;
            len = number.value.length;
        }
        else index++;
    }
}


function IsValidTime(control) {
    var control1 = document.getElementById(control).value;
    var hour = control1.substr(0, 2);
    var separate = control1.substr(2, 1);
    var minute = control1.substr(3, 2);
    re = /^\d{1,2}:\d{2}([ap]m)?$/;
    if (!control1.match(re) || control1.length < 5 || hour > 23 || separate != ":" || minute > 59)
        return false;

    return true;
}